package cn.likole.oj;

import org.nutz.mvc.annotation.*;
import org.nutz.mvc.ioc.provider.ComboIocProvider;
import org.nutz.plugins.apidoc.ApidocUrlMapping;
import org.nutz.plugins.apidoc.annotation.Api;

import javax.servlet.http.HttpSession;

/**
 * Created by likole on 7/23/18.
 */
@SetupBy(value = MainSetup.class)
@IocBy(type = ComboIocProvider.class, args = {"*js", "ioc/",
        "*anno", "cn.likole.oj",
        "*tx", // 事务拦截 aop
        "*async"}) // 异步执行aop
@Modules()
@Ok("json:full")
@Fail("jsp:jsp.500")
//@Filters(@By(type = CrossOriginFilter.class))
@UrlMappingBy(ApidocUrlMapping.class)
@Api(name = "主模块")
public class MainModule {

    @At("/")
    @Ok("re")
    public String index(HttpSession session) {
        if (session.getAttribute("uid") == null) return ">>:/user/loginpage";
        if (session.getAttribute("stage0") != null) return ">>:/tutorial/index";
        return "jsp:500";
    }

    /**
     * 给判题机使用的空返回内容
     *
     * @return
     */
    @At
    @Ok("raw")
    public String blank() {
        return "0";
    }

}
